package com.hailong.zyt.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hailong.zyt.beans.CourseUncheck;
import com.hailong.zyt.beans.Teacher;
import com.hailong.zyt.service.CourseUncheckService;
import com.hailong.zyt.service.impl.CourseUncheckServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hailong
 * @since 2021-06-08
 */
@Controller
public class CourseUncheckController {

    private CourseUncheckService courseUncheckService;

    /**
     * 展示学生选课请求
     * ---teaRequest.html
     * */
    @GetMapping("/teacher/RequestList")
    public String showChooseRequestList(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
                                        HttpSession session,
                                        Model model){
        Teacher teacher = (Teacher) session.getAttribute("teacher");
        IPage<CourseUncheck> pages = courseUncheckService.getRequestList(teacher.getTeaId(), pn);
        model.addAttribute("pages", pages);
        return "/teacher/course/teaRequest";
    }

    /**
     * 同意/拒绝选课请求
     * */
    @GetMapping("/teacher/accept")
    public String accept(@RequestParam("couId") Long couId,
                         @RequestParam("teaId") Long teaId,
                         @RequestParam("stuId") Long stuId){
        courseUncheckService.acceptChosen(couId, teaId, stuId);
        return "redirect:/teacher/RequestList";
    }
    @GetMapping("/teacher/refuse")
    public String refuse(@RequestParam("couId") Long couId,
                         @RequestParam("teaId") Long teaId,
                         @RequestParam("stuId") Long stuId){
        courseUncheckService.refuseChosen(couId, teaId, stuId);
        return "redirect:/teacher/RequestList";
    }

    /**
     * 发出选课请求
     * */
    @GetMapping("/student/choose")
    public String choose(@RequestParam("couId") Long couId,
                         @RequestParam("teaId") Long teaId,
                         @RequestParam("stuId") Long stuId){
        CourseUncheck courseUncheck = new CourseUncheck(couId, teaId, stuId);
        courseUncheckService.save(courseUncheck);
        return "redirect:/student/courses";
    }

    @Autowired
    public void setCourseUncheckService(CourseUncheckServiceImpl courseUncheckService) {
        this.courseUncheckService = courseUncheckService;
    }
}

